home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / print / p1123mz4.zip / SQUARE.CPP < prev    next >
C/C++ Source or Header  |  1994-03-02  |  5KB  |  147 lines

  1. //
  2. //       This program will generate a three dimensional maze on a Panasonic 1123
  3. //  printer.  A different random number seed will produce a different maze.
  4. //
  5. //       Written by James L. Dean
  6. //                  406 40th Street
  7. //                  New Orleans, LA 70124-1532
  8. //
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <math.h>
  12. #include <stdlib.h>
  13. #include <conio.h>
  14. #include <time.h>
  15. #include <iostream.h>
  16. #include "oracle.h"
  17. #include "cell.h"
  18. #include "titillat.h"
  19. #include "sqrmaze.h"
  20. #include "plot3d.h"
  21. #include "x1123x3d.h"
  22.  
  23. #ifndef TRUE
  24. #define TRUE -1
  25. #endif
  26. #ifndef FALSE
  27. #define FALSE 0
  28. #endif
  29.  
  30. // maze constants
  31. #define PIXELS_PER_ROOM   60
  32. #define RESOLUTION         4  // larger values takes more time (and virtual
  33.                               // memory) but produce a better image
  34.  
  35. static int    external_to_plot(double,double);
  36. static double f(double,double);
  37.        int    main(int,char **);
  38. static int    red(double,double);
  39.  
  40. extern unsigned _stklen=0x8000;
  41.        maze     *maze_ptr;
  42.  
  43. int main(
  44.   int argc,
  45.   char *argv[])
  46.     {
  47.       static   double   bias;
  48.       static   int      fatal_error;
  49.       static   int      num_columns;
  50.       static   int      num_rows;
  51.       static   double   light_x;
  52.       static   double   light_y;
  53.       static   double   light_z;
  54.       static   double   rotation;
  55.                time_t   start_time;
  56.                time_t   stop_time;
  57.       static   double   tilt;
  58.       static   x1123x3d *x1123x3d_ptr;
  59.  
  60.       fatal_error=FALSE;
  61.       if ((argc == 2) || ((argc == 3) && (atof(argv[2]) > 0.0)))
  62.         {
  63.           time(&start_time);
  64.           if (argc == 2)
  65.             bias=0.3;
  66.           else
  67.             bias=atof(argv[2]);
  68.           x1123x3d_ptr=new x1123x3d();
  69.           num_columns=(x1123x3d_ptr->num_x_pixels())/PIXELS_PER_ROOM;
  70.           num_rows=(int) (((2.0/sqrt(3.0))
  71.            *(x1123x3d_ptr->aspect_ratio())
  72.            *((double) (x1123x3d_ptr->num_y_pixels())))
  73.            /((double) PIXELS_PER_ROOM));
  74.           maze_ptr=new maze(num_rows,num_columns,RESOLUTION,argv[1]);
  75.           if (maze_ptr->constructed())
  76.             {
  77.               rotation=(double) 0.0;
  78.               tilt=(double) 30.0;
  79.               light_x=(double) 1.5;
  80.               light_y=(double) -1.0;
  81.               light_z=(double) 2.6;
  82.               if (x1123x3d_ptr->prepare_plot(f,
  83.                maze_ptr->x_min(),maze_ptr->x_max(),
  84.                maze_ptr->y_min(),maze_ptr->y_max(),external_to_plot,red,
  85.                maze_ptr->num_x_divisions(),maze_ptr->num_y_divisions(),
  86.                rotation,tilt,light_x,light_y,light_z))
  87.                 if (x1123x3d_ptr->plot("SQUARE.MAZ",FALSE,TRUE,bias))
  88.                   if (x1123x3d_ptr->plot("SQUARE.SOL",TRUE,TRUE,bias))
  89.                     {
  90.                       time(&stop_time);
  91.                       cout << '\n' << "     It took " << stop_time-start_time
  92.                        << " seconds to generate the maze and its solution."
  93.                        << '\n' << '\n'
  94.                        << "     If LPT1: is your Panasonic 1123, "
  95.                        << "\"COPY /B SQUARE.MAZ LPT1:\"" << '\n'
  96.                        << "and \"COPY /B SQUARE.SOL LPT1:\"." << '\n';
  97.                     }
  98.                   else
  99.                     fatal_error=TRUE;
  100.                 else
  101.                   fatal_error=TRUE;
  102.               else
  103.                 fatal_error=TRUE;
  104.             }
  105.           else 
  106.             fatal_error=TRUE;
  107.           delete maze_ptr;
  108.           delete x1123x3d_ptr;
  109.         }
  110.       else
  111.         cout << '\n' << "     This program will generate a three dimensional "
  112.          << "maze suitable for " << '\n' << "printing on a Panasonic 1123 "
  113.          << "printer.  It writes the maze to the file" << '\n'
  114.          << "\"SQUARE.MAZ\" and the solution to \"SQUARE.SOL\"." << '\n' << '\n'
  115.          << "     If LPT1: is your Panasonic 1123, \"COPY /B SQUARE.MAZ "
  116.          << "LPT1:\" to" << '\n' << "print the maze and \"COPY /B SQUARE.SOL "
  117.          << "LPT1:\" to print the solution." << '\n' << '\n'
  118.          << "     Usage:  SQUARE <random number seed> [<bias>]" << '\n' << '\n'
  119.          << "       A different <random number seed> will produce a different "
  120.          << "maze." << '\n' << '\n' << "       <bias> adjusts the contrast.  "
  121.          << "It defaults to 0.3 for a new ribbon." << '\n'
  122.          << "       0.5 or higher should be used for a worn ribbon." << '\n'
  123.          << '\n' << "     Example:  SQUARE 61743076 0.5" << '\n';
  124.       return(fatal_error);
  125.     }
  126.  
  127. static int external_to_plot(
  128.   double x,
  129.   double y)
  130.     {
  131.        return maze_ptr->external_to_maze(x,y);
  132.     }
  133.  
  134. static int red(
  135.   double x,
  136.   double y)
  137.     {
  138.        return maze_ptr->part_of_solution(x,y);
  139.     }
  140.  
  141. static double f(
  142.   double x,
  143.   double y)
  144.     {
  145.        return maze_ptr->f(x,y);
  146.     }
  147.